package com.example.seakdreamandroid.sleep.entity;

import android.util.Log;

import com.example.seakdreamandroid.entity.AudioInfo;
import com.example.seakdreamandroid.playHistory.PlayHistory;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class SleepInfo implements Serializable {
    private String userId;
    private String sleepId;
    private String asleepTime;
    private String awakeTime;
    public static final String[] dayStrOfWeek = new String[]{"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
    public static final int MINUTE_MILL = 60000;
    public static final int DAY_MILL = 24*60*MINUTE_MILL;
    public static final int SECOND_MILL = 1000;
//    private List<PlayHistory> audio_id;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getSleepId() {
        return sleepId;
    }

    public void setSleepId(String sleepId) {
        this.sleepId = sleepId;
    }

    public String getAsleepTime() {
        return asleepTime;
    }

    public void setAsleepTime(String asleepTime) {
        this.asleepTime = asleepTime;
    }

    public String getAwakeTime() {
        return awakeTime;
    }

    public void setAwakeTime(String awakeTime) {
        this.awakeTime = awakeTime;
    }

    //返回持续分钟数
    public long getDuration() {
        try{
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date start = parse.parse(asleepTime);
            Date end = parse.parse(awakeTime);
            return (end.getTime() - start.getTime())/MINUTE_MILL;
        }catch(ParseException e){
            e.printStackTrace();
        }
        return -1;
    }

    public String getFormatDate() {
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
            Date start = parse.parse(asleepTime);
            return dateFormat.format(start);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public String getDayOfWeek() {
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date start = parse.parse(asleepTime);
            Calendar temp = Calendar.getInstance();
            temp.setTime(start);
            return dayStrOfWeek[temp.get(Calendar.DAY_OF_WEEK)-1];
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public String getFormatStartTime() {
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
            Date start = parse.parse(asleepTime);
            return timeFormat.format(start);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public String getFormatEndTime() {
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
            Date end = parse.parse(awakeTime);
            return timeFormat.format(end);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public long getAsleepTimeInMill(){
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date start = parse.parse(asleepTime);
//            Log.i("SleepInfo",start.getTime()+"");
            return start.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public long getAwakeTimeInMill(){
        try {
            SimpleDateFormat parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date end = parse.parse(awakeTime);
//            Log.i("SleepInfo",end.getTime()+"");
            return end.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

//    public String getAudio_id() {
//        return audio_id;
//    }
//
//    public void setAudio_id(String audio_id) {
//        this.audio_id = audio_id;
//    }
}
